package com.itheima.controller;

import com.itheima.dto.MenusDto;
import com.itheima.dto.PermissionDto;
import com.itheima.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class MenusController {

    @Autowired
    private MenusService menusService;

    /**
     *
     * Description:
     *菜单列表
     * @param:  * @param
     * @return: {@link List<  PermissionDto >}
     */
    @GetMapping
    public List<PermissionDto> menusPage(){

        return   menusService.menusPage();

    }

    /**
     *
     * Description:
     *修改菜单
     * @param:  * @param id
     * @param menusDto
     * @return: {@link String}
     */
    @PutMapping("/{id}")
    public String modifyMenus(@PathVariable Long id ,@RequestBody MenusDto menusDto){
           menusDto.setId(id);
           menusService.modifyMenus(menusDto);
        return "{'success':true}";
    }

    /**
     *
     * Description:
     *删除菜单
     * @param:  * @param id
     * @return: {@link String}
     */
    @DeleteMapping("/{id}")
    public String removeMenus(@PathVariable Integer id){
        menusService.removeMenus(id);
        return "{'success':true}";
    }

    /**
     *
     * Description:
     *添加菜单
     * @param:  * @param menusDto
     * @return: {@link String}
     */
    @PostMapping
    public String addMenus(@RequestBody MenusDto menusDto){
        menusService.addMenus(menusDto);
        return "{'success':true}";
    }

    /**
     *
     * Description:
     *菜单详情
     * @param:  * @param id
     * @return: {@link MenusDto}
     */
    @GetMapping("/{id}")
    public MenusDto findMenusById(@PathVariable Integer id){
       return menusService.findMenusById(id);
    }
}
